import { getUnitDictList } from "@/api/common";
import { exportUrl } from "@/api/order/mesRequirePlan";
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
  },
  {
    name: $i18n.t("mesRequirePlan.scheduling"),
    type: "success",
    icon: "el-icon-circle-check",
    handleName: "scheduling", //点击时返回的标识
    disabled: (data) => {
      return data.length != 1;
    },
  },
  {
    name: $i18n.t("mesRequirePlan.seniorScheduling"),
    type: "success",
    icon: "el-icon-circle-check",
    handleName: "seniorScheduling", //点击时返回的标识
    isMultiple: true,
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
    show: (data) => {
      return !data.scheduledCode;
    },
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    orderNoQuery: {
      type: "input",
      label: $i18n.t("mesRequirePlan.orderNoQuery"),
    },
    prodNameQuery: {
      type: "input",
      label: $i18n.t("mesRequirePlan.prodNameQuery"), // 产品名称或编码
    },
    customerName: {
      type: "input",
      label: $i18n.t("mesRequirePlan.customerName"),
    },
    deliveryDate: {
      type: "daterange",
      label: $i18n.t("mesRequirePlan.deliveryDate"),
      attrs: {
        valueFormat: "yyyy-MM-dd",
        searchArrKey: ["deliveryDateMin", "deliveryDateMax"],
      },
    },
  },
};
// 新增/删除表单配置
export const addFormDialog = {
  data() {
    const that = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        formDesc: {
          customerName: {
            type: "input",
            label: $i18n.t("mesRequirePlan.customerName2"),
            layout: 12,
            required: false,
          },
          mesRequirePlanList: {
            label: $i18n.t("common.specifiedProduct"),
            layout: 24,
            required: true,
            type: "table-editor",
            attrs: {
              // 上方,按钮,render
              topBtnRender: (h, solt) => {
                return (
                  <el-button
                    type="primary"
                    onClick={() => {
                      that.addList();
                    }}
                  >
                    {$i18n.t("common.add")}
                  </el-button>
                );
              },
              // 校检规则
              rules: {
                quantity: {
                  required: true,
                  message: $i18n.t("mesRequirePlan.enterReqQuantity"),
                },
                deliveryDate: {
                  required: true,
                  message: $i18n.t("mesRequirePlan.enterDeliveryDate"),
                },
              },
              isShowAdd: false,
              columns: [
                {
                  type: "index",
                  width: 50,
                  align: "center",
                  label: $i18n.t("common.order"),
                },
                {
                  prop: "goodsCode",
                  label: $i18n.t("mesRequirePlan.goodsCode"),
                  align: "center",
                  minWidth: 140,
                  showOverflowTooltip: true,
                },
                {
                  prop: "goodsName",
                  label: $i18n.t("mesRequirePlan.goodsName"),
                  minWidth: 140,
                  align: "center",
                  showOverflowTooltip: true,
                },
                // {
                //   prop: "seriesCode",
                //   label: "系列编码",
                //   minWidth: 120,
                //   showOverflowTooltip: true,
                // },
                // {
                //   prop: "seriesName",
                //   label: "系列名称",
                //   minWidth: 120,
                //   showOverflowTooltip: true,
                // },

                {
                  prop: "unit",
                  label: $i18n.t("mesRequirePlan.unit"),
                  align: "center",
                  showOverflowTooltip: true,
                },
                {
                  prop: "quantity",
                  label: $i18n.t("mesRequirePlan.quantity"),
                  align: "center",
                  minWidth: 150,
                  className: "required",
                  content: {
                    type: "el-input-number",
                    attrs: {
                      min: 1,
                      controlsPosition: "right",
                    },
                  },
                },
                {
                  prop: "deliveryDate",
                  label: $i18n.t("mesRequirePlan.deliveryDate"),
                  minWidth: 245,
                  align: "center",
                  className: "required",
                  content: {
                    type: "el-date-picker",
                    attrs: {
                      placeholder: $i18n.t("mesRequirePlan.selectDeliveryDate"),
                      "value-format": "yyyy-MM-dd",
                      "picker-options": {
                        disabledDate: (time) =>
                          time.getTime() <
                          new Date(new Date().setHours(0, 0, 0, 0)),
                      },
                    },
                  },
                },
                {
                  prop: "remark",
                  label: $i18n.t("mesRequirePlan.remark"),
                  align: "center",
                  minWidth: 150,
                  content: {
                    type: "el-input",
                    attrs: { type: "textarea" },
                  },
                },
              ],

              // 新行默认值
              newColumnValue: {
                quantity: 0,
                deliveryDate: "",
              },
            },
          },
        },
      },
    };
  },
};
// 编辑弹窗
export const editFormDialog = {
  data() {
    const self = this;
    return {
      editFormDescDialog: {
        isShowSubmitBtn: true,
        formDesc: {
          customerName: {
            layout: 24,
            type: "input",
            label: $i18n.t("mesRequirePlan.customer"),
          },
          prodName: {
            layout: 24,
            type: "input",
            label: $i18n.t("common.specifiedProduct"),
            required: true,
          },
          quantity: {
            layout: 24,
            type: "number",
            label: $i18n.t("common.quantity"),
            required: true,
            attrs: {
              min: 1,
              controlsPosition: "right",
            },
          },
          deliveryDate: {
            layout: 24,
            type: "date",
            label: $i18n.t("common.planDeliveryDate"),
            required: true,
            attrs: {
              valueFormat: "yyyy-MM-dd",
              "picker-options": {
                disabledDate: (time) =>
                  time.getTime() < new Date(new Date().setHours(0, 0, 0, 0)),
              },
            },
          },
          unitCode: {
            type: "select",
            label: $i18n.t("mesGateOrderWhite.measureUnit"),
            layout: 24,
            required: true,
            prop: {
              value: "value",
              text: "description",
            },
            options: async () => {
              const list = await getUnitDictList();
              self.getDictList = list.data.result;
              return list.data.result;
            },
            on: {
              change: (val) => {
                this.handelSelectUnit(val);
              },
            },
          },
          remark: {
            layout: 24,
            label: $i18n.t("common.remark"),
            type: "textarea",
          },
        },
      },
    };
  },
  methods: {
    handelSelectUnit(val) {
      let description = (
        this.getDictList.find((i) => i.value == val) || { description: "" }
      ).description;
      this.$set(this.editFormDataDialog, "unit", description);
    },
  },
};
